<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222"><meta name="generator" content="Hexo 7.3.0">

  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32.ico">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16.ico">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" integrity="sha256-wiz7ZSCn/btzhjKDQBms9Hx4sSeUYsDrTLg7roPstac=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.28/fancybox/fancybox.css" integrity="sha256-6cQIC71/iBIYXFK+0RHAvwmjwWzkWd+r7v/BX3/vZDc=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/themes/green/pace-theme-minimal.css">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/pace.min.js" integrity="sha256-gqd7YTjg/BtfqWSwsJOvndl0Bxc8gFImLEkXQT8+qj0=" crossorigin="anonymous"></script>

<script class="next-config" data-name="main" type="application/json">{"hostname":"sumumm.github.io","root":"/","images":"/images","scheme":"Gemini","darkmode":false,"version":"8.19.2","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":{"enable":true,"style":"mac"},"fold":{"enable":true,"height":300},"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":true,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":true,"transition":{"menu_item":"fadeInDown","post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false}}</script><script src="/js/config.js"></script>

    <meta name="description" content="本文主要是linux——内核移植的相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。">
<meta property="og:type" content="article">
<meta property="og:title" content="LV09-03-linux-02-linux内核移植">
<meta property="og:url" content="https://sumumm.github.io/post/2b49c53b.html">
<meta property="og:site_name" content="苏木">
<meta property="og:description" content="本文主要是linux——内核移植的相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV09-uboot%E4%B8%8Elinux/LV09-03-linux-02-linux%E5%86%85%E6%A0%B8%E7%A7%BB%E6%A4%8D/img/image-20220821125151346.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV09-uboot%E4%B8%8Elinux/LV09-03-linux-02-linux%E5%86%85%E6%A0%B8%E7%A7%BB%E6%A4%8D/img/image-20220821125437145.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV09-uboot%E4%B8%8Elinux/LV09-03-linux-02-linux%E5%86%85%E6%A0%B8%E7%A7%BB%E6%A4%8D/img/image-20220821130122961.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV09-uboot%E4%B8%8Elinux/LV09-03-linux-02-linux%E5%86%85%E6%A0%B8%E7%A7%BB%E6%A4%8D/img/image-20220821210813855.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV09-uboot%E4%B8%8Elinux/LV09-03-linux-02-linux%E5%86%85%E6%A0%B8%E7%A7%BB%E6%A4%8D/img/image-20220821211016125.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV09-uboot%E4%B8%8Elinux/LV09-03-linux-02-linux%E5%86%85%E6%A0%B8%E7%A7%BB%E6%A4%8D/img/image-20220821211129157.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV09-uboot%E4%B8%8Elinux/LV09-03-linux-02-linux%E5%86%85%E6%A0%B8%E7%A7%BB%E6%A4%8D/img/image-20220821144829754.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV09-uboot%E4%B8%8Elinux/LV09-03-linux-02-linux%E5%86%85%E6%A0%B8%E7%A7%BB%E6%A4%8D/img/image-20220821145235696.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV09-uboot%E4%B8%8Elinux/LV09-03-linux-02-linux%E5%86%85%E6%A0%B8%E7%A7%BB%E6%A4%8D/img/image-20220821145924539.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV09-uboot%E4%B8%8Elinux/LV09-03-linux-02-linux%E5%86%85%E6%A0%B8%E7%A7%BB%E6%A4%8D/img/image-20220821151028001.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV09-uboot%E4%B8%8Elinux/LV09-03-linux-02-linux%E5%86%85%E6%A0%B8%E7%A7%BB%E6%A4%8D/img/image-20220821151631835.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV09-uboot%E4%B8%8Elinux/LV09-03-linux-02-linux%E5%86%85%E6%A0%B8%E7%A7%BB%E6%A4%8D/img/image-20220821152715000.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV09-uboot%E4%B8%8Elinux/LV09-03-linux-02-linux%E5%86%85%E6%A0%B8%E7%A7%BB%E6%A4%8D/img/image-20220822120944803.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV09-uboot%E4%B8%8Elinux/LV09-03-linux-02-linux%E5%86%85%E6%A0%B8%E7%A7%BB%E6%A4%8D/img/image-20220822143645370.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV09-uboot%E4%B8%8Elinux/LV09-03-linux-02-linux%E5%86%85%E6%A0%B8%E7%A7%BB%E6%A4%8D/img/image-20220822144449480.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV09-uboot%E4%B8%8Elinux/LV09-03-linux-02-linux%E5%86%85%E6%A0%B8%E7%A7%BB%E6%A4%8D/img/image-20220822144724519.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV09-uboot%E4%B8%8Elinux/LV09-03-linux-02-linux%E5%86%85%E6%A0%B8%E7%A7%BB%E6%A4%8D/img/image-20220822151946505.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV09-uboot%E4%B8%8Elinux/LV09-03-linux-02-linux%E5%86%85%E6%A0%B8%E7%A7%BB%E6%A4%8D/img/image-20220822152625842.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV09-uboot%E4%B8%8Elinux/LV09-03-linux-02-linux%E5%86%85%E6%A0%B8%E7%A7%BB%E6%A4%8D/img/image-20220822153229722.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV09-uboot%E4%B8%8Elinux/LV09-03-linux-02-linux%E5%86%85%E6%A0%B8%E7%A7%BB%E6%A4%8D/img/image-20220822161009551.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV09-uboot%E4%B8%8Elinux/LV09-03-linux-02-linux%E5%86%85%E6%A0%B8%E7%A7%BB%E6%A4%8D/img/image-20220822165230442.png">
<meta property="article:published_time" content="2023-07-07T11:34:14.000Z">
<meta property="article:modified_time" content="2025-06-13T16:25:57.002Z">
<meta property="article:author" content="苏木">
<meta property="article:tag" content="LV09-uboot与linux">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV09-uboot%E4%B8%8Elinux/LV09-03-linux-02-linux%E5%86%85%E6%A0%B8%E7%A7%BB%E6%A4%8D/img/image-20220821125151346.png">


<link rel="canonical" href="https://sumumm.github.io/post/2b49c53b.html">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"https://sumumm.github.io/post/2b49c53b.html","path":"post/2b49c53b.html","title":"LV09-03-linux-02-linux内核移植"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>LV09-03-linux-02-linux内核移植 | 苏木</title>
  








    <script src="/js/browser_tools_disable.js"></script>

  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
<!-- hexo injector head_end start --><link rel="stylesheet" href="https://unpkg.com/hexo-next-tags-plus@latest/lib/tag_plus.css" media="defer" onload="this.media='all'"><!-- hexo injector head_end end --></head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <div class="column">
      <header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">苏木</p>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">我的学习之路</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger" aria-label="搜索" role="button">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>苏木的家</a></li><li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类页<span class="badge">42</span></a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档页<span class="badge">673</span></a></li><li class="menu-item menu-item-flink"><a href="/flink/" rel="section"><i class="fa fa-link fa-fw"></i>友人帐</a></li><li class="menu-item menu-item-about"><a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于我</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</header>
        
  
  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%80%E3%80%81%E6%96%87%E4%BB%B6%E5%87%86%E5%A4%87"><span class="nav-text">一、文件准备</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-linux%E5%86%85%E6%A0%B8%E6%BA%90%E7%A0%81"><span class="nav-text">1. linux内核源码</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-1-%E6%BA%90%E7%A0%81%E8%8E%B7%E5%8F%96%E9%80%94%E5%BE%84"><span class="nav-text">1.1 源码获取途径</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#1-2-%E8%8E%B7%E5%8F%96%E6%BA%90%E7%A0%81%E6%96%87%E4%BB%B6"><span class="nav-text">1.2 获取源码文件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#1-3-%E6%8B%B7%E8%B4%9D%E8%A7%A3%E5%8E%8B"><span class="nav-text">1.3 拷贝解压</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-Busybox%E6%BA%90%E7%A0%81"><span class="nav-text">2. Busybox源码</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#2-1-%E6%BA%90%E7%A0%81%E8%8E%B7%E5%8F%96%E9%80%94%E5%BE%84"><span class="nav-text">2.1 源码获取途径</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-2-%E8%8E%B7%E5%8F%96%E6%BA%90%E7%A0%81%E6%96%87%E4%BB%B6"><span class="nav-text">2.2 获取源码文件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-3-%E6%8B%B7%E8%B4%9D%E8%A7%A3%E5%8E%8B"><span class="nav-text">2.3 拷贝解压</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-rootfs"><span class="nav-text">3. rootfs</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#3-1-%E6%96%87%E4%BB%B6%E8%8E%B7%E5%8F%96"><span class="nav-text">3.1 文件获取</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-2-%E6%8B%B7%E8%B4%9D%E8%A7%A3%E5%8E%8B"><span class="nav-text">3.2 拷贝解压</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%BA%8C%E3%80%81Linux%E5%86%85%E6%A0%B8%E7%A7%BB%E6%A4%8D"><span class="nav-text">二、Linux内核移植</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E6%8C%87%E5%AE%9A%E4%BA%A4%E5%8F%89%E7%BC%96%E8%AF%91%E5%B7%A5%E5%85%B7"><span class="nav-text">1. 指定交叉编译工具</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-linux%E5%86%85%E6%A0%B8%E7%BC%96%E8%AF%91"><span class="nav-text">2. linux内核编译</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#2-1-%E5%86%85%E6%A0%B8%E9%85%8D%E7%BD%AE"><span class="nav-text">2.1 内核配置</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#2-1-1-%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6"><span class="nav-text">2.1.1 配置文件</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-1-2-%E4%BF%AE%E6%94%B9%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6"><span class="nav-text">2.1.2 修改配置文件</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-2-%E6%8C%87%E5%AE%9A%E4%BD%BF%E7%94%A8%E7%9A%84%E5%A4%84%E7%90%86%E5%99%A8"><span class="nav-text">2.2 指定使用的处理器</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-3-%E7%BC%96%E8%AF%91%E5%86%85%E6%A0%B8"><span class="nav-text">2.3 编译内核</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-4-%E7%BC%96%E8%AF%91%E5%86%85%E6%A0%B8%E6%A8%A1%E5%9D%97"><span class="nav-text">2.4 编译内核模块</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-%E8%AE%BE%E5%A4%87%E6%A0%91%E7%BC%96%E8%AF%91"><span class="nav-text">3. 设备树编译</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#3-1-%E6%B7%BB%E5%8A%A0%E8%AE%BE%E5%A4%87%E6%A0%91%E6%BA%90%E7%A0%81%E6%96%87%E4%BB%B6"><span class="nav-text">3.1 添加设备树源码文件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-2-%E4%BF%AE%E6%94%B9%E7%9B%B8%E5%BA%94Makefile"><span class="nav-text">3.2 修改相应Makefile</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-3-%E7%BC%96%E8%AF%91%E8%AE%BE%E5%A4%87%E6%A0%91"><span class="nav-text">3.3 编译设备树</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-%E5%86%85%E6%A0%B8%E5%90%AF%E5%8A%A8%E6%B5%8B%E8%AF%95"><span class="nav-text">4. 内核启动测试</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%89%E3%80%81%E5%9F%BA%E6%9C%AC%E9%A9%B1%E5%8A%A8%E7%A7%BB%E6%A4%8D"><span class="nav-text">三、基本驱动移植</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E4%B8%B2%E5%8F%A3%E9%A9%B1%E5%8A%A8"><span class="nav-text">1. 串口驱动</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E7%BD%91%E5%8D%A1%E9%A9%B1%E5%8A%A8"><span class="nav-text">2. 网卡驱动</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#2-1-%E4%BF%AE%E6%94%B9%E5%86%85%E6%A0%B8%E9%85%8D%E7%BD%AE"><span class="nav-text">2.1 修改内核配置</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-2-%E4%BF%AE%E6%94%B9%E8%AE%BE%E5%A4%87%E6%A0%91"><span class="nav-text">2.2 修改设备树</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-3-%E4%BF%AE%E6%94%B9%E6%97%B6%E9%92%9F%E9%85%8D%E7%BD%AE"><span class="nav-text">2.3 修改时钟配置</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-4-%E4%BF%AE%E6%94%B9eMMC%E9%85%8D%E7%BD%AE"><span class="nav-text">2.4 修改eMMC配置</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-%E7%BC%96%E8%AF%91%E5%86%85%E6%A0%B8%E5%92%8C%E8%AE%BE%E5%A4%87%E6%A0%91"><span class="nav-text">3. 编译内核和设备树</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-%E5%86%85%E6%A0%B8%E5%90%AF%E5%8A%A8%E6%B5%8B%E8%AF%95-1"><span class="nav-text">4. 内核启动测试</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%9B%9B%E3%80%81%E6%A0%B9%E6%96%87%E4%BB%B6%E7%B3%BB%E7%BB%9F%E7%A7%BB%E6%A4%8D"><span class="nav-text">四、根文件系统移植</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E9%85%8D%E7%BD%AEbusybox"><span class="nav-text">1. 配置busybox</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E7%BC%96%E8%AF%91busybox"><span class="nav-text">2. 编译busybox</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-%E5%AE%89%E8%A3%85busybox"><span class="nav-text">3. 安装busybox</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-%E6%B7%BB%E5%8A%A0lib%E5%BA%93"><span class="nav-text">4. 添加lib库</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#4-1-%E6%8B%B7%E8%B4%9Dlib%E5%BA%93"><span class="nav-text">4.1 拷贝lib库</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-2-%E5%88%A0%E9%99%A4lib%E9%9D%99%E6%80%81%E5%BA%93"><span class="nav-text">4.2 删除lib静态库</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-3-%E5%88%A0%E9%99%A4%E5%85%B1%E4%BA%AB%E5%BA%93%E4%B8%AD%E7%AC%A6%E5%8F%B7%E8%A1%A8"><span class="nav-text">4.3 删除共享库中符号表</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#5-%E5%88%9B%E5%BB%BA%E5%85%B6%E4%BB%96%E7%9B%AE%E5%BD%95"><span class="nav-text">5. 创建其他目录</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#6-%E6%A0%B9%E6%96%87%E4%BB%B6%E7%B3%BB%E7%BB%9F%E5%88%9D%E6%AD%A5%E6%B5%8B%E8%AF%95"><span class="nav-text">6. 根文件系统初步测试</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#7-%E5%AE%8C%E5%96%84%E6%A0%B9%E6%96%87%E4%BB%B6%E7%B3%BB%E7%BB%9F"><span class="nav-text">7. 完善根文件系统</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#7-1-etc%E7%9B%AE%E5%BD%95%E4%BB%8B%E7%BB%8D"><span class="nav-text">7.1 etc目录介绍</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#7-1-1-%E7%9B%AE%E5%BD%95%E7%BB%93%E6%9E%84"><span class="nav-text">7.1.1 目录结构</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#7-1-2-rcS%E6%96%87%E4%BB%B6"><span class="nav-text">7.1.2 rcS文件</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#7-1-3-fstab%E6%96%87%E4%BB%B6"><span class="nav-text">7.1.3 fstab文件</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#7-1-4-inittab%E6%96%87%E4%BB%B6"><span class="nav-text">7.1.4 inittab文件</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#7-2-etc%E7%9B%AE%E5%BD%95%E5%88%9B%E5%BB%BA"><span class="nav-text">7.2 etc目录创建</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#7-3-%E6%A0%B9%E6%96%87%E4%BB%B6%E7%B3%BB%E7%BB%9F%E6%B5%8B%E8%AF%95"><span class="nav-text">7.3 根文件系统测试</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#8-busybox%E4%B8%AD%E6%96%87%E5%AD%97%E7%AC%A6%E6%94%AF%E6%8C%81"><span class="nav-text">8. busybox中文字符支持</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#8-1-printable-string-c%E6%96%87%E4%BB%B6%E4%BF%AE%E6%94%B9"><span class="nav-text">8.1 printable_string.c文件修改</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#8-2-unicode-c%E6%96%87%E4%BB%B6%E4%BF%AE%E6%94%B9"><span class="nav-text">8.2 unicode.c文件修改</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#8-3-busybox%E9%85%8D%E7%BD%AE"><span class="nav-text">8.3 busybox配置</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#8-4-%E9%87%8D%E6%96%B0%E5%88%B6%E4%BD%9C%E6%A0%B9%E6%96%87%E4%BB%B6%E7%B3%BB%E7%BB%9F"><span class="nav-text">8.4 重新制作根文件系统</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#8-5-%E4%B8%AD%E6%96%87%E6%94%AF%E6%8C%81%E6%B5%8B%E8%AF%95"><span class="nav-text">8.5 中文支持测试</span></a></li></ol></li></ol></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="苏木"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">苏木</p>
  <div class="site-description" itemprop="description">莫道桑榆晚，为霞尚满天</div>
</div>
<div class="site-state-wrap animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">673</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">42</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
        <span class="site-state-item-count">43</span>
        <span class="site-state-item-name">标签</span>
      </div>
  </nav>
</div>
  <div class="links-of-author animated">
      <span class="links-of-author-item">
        <a href="https://github.com/sumumm" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;sumumm" rel="noopener me" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
  </div>

        </div>
      </div>
    </div>

    
  </aside>


    </div>

    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://sumumm.github.io/post/2b49c53b.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="苏木">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏木">
      <meta itemprop="description" content="莫道桑榆晚，为霞尚满天">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="LV09-03-linux-02-linux内核移植 | 苏木">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          LV09-03-linux-02-linux内核移植
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2023-07-07 19:34:14" itemprop="dateCreated datePublished" datetime="2023-07-07T19:34:14+08:00">2023-07-07</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/" itemprop="url" rel="index"><span itemprop="name">嵌入式开发</span></a>
        </span>
          ，
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/" itemprop="url" rel="index"><span itemprop="name">01HQ课程体系</span></a>
        </span>
          ，
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV09-uboot%E4%B8%8Elinux/" itemprop="url" rel="index"><span itemprop="name">LV09-uboot与linux</span></a>
        </span>
    </span>

  
    <span class="post-meta-break"></span>
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>10k</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>36 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody"><p>本文主要是linux——内核移植的相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。</p>
<span id="more"></span>

<!-- Photo: https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV09-uboot%E4%B8%8Elinux/LV09-03-linux-02-linux%E5%86%85%E6%A0%B8%E7%A7%BB%E6%A4%8D/img/ -->

<details class="folding-tag" blue><summary> 点击查看使用工具及版本 </summary>
              <div class='content'>
              <table>    <tr>        <td align="center" width=150px>Windows</td>        <td align="left">windows11</td>    </tr>    <tr>        <td align="center">Ubuntu</td>        <td align="left">Ubuntu16.04的64位版本</td>      </tr>    <tr>        <td align="center">VMware® Workstation 16 Pro</td>        <td align="left">16.2.3 build-19376536</td>      </tr>    <tr>        <td align="center">SecureCRT</td>        <td align="left">Version 8.7.2 (x64 build 2214)   -   正式版-2020年5月14日</td>      </tr>    <tr>        <td align="center" width=150>Linux开发板</td>        <td align="left">华清远见 底板: FS4412_DEV_V5 核心板: FS4412 V2</td>      </tr>    <tr>        <td align="center" width=150>u-boot</td>        <td align="left">2013.01</td>      </tr></table>
              </div>
            </details>

<details class="folding-tag" blue><summary> 点击查看本文参考资料 </summary>
              <div class='content'>
              <table>    <tr><td align="center">参考方向</td><td align="center">参考原文</td></tr>    <tr><td align="left">Linux内核移植</td><td align="left">实验7 Linux内核移植</td></tr>    <tr><td align="left">网卡驱动移植</td><td align="left">实验8 网卡驱动移植</td></tr>    <tr><td align="left">根文件系统移植</td><td align="left">实验9 根文件系统移植</td></tr>    <tr><td align="left">驱动开发指南</td><td align="left"><a href="http://47.111.11.73/docs/boards/arm-linux/zdyz-i.mx6ull.html#i-mx6ull-linux" target="_blank">i.MX6ULL Linux阿尔法开发板资料 <i class="fa fa-external-link-alt"></i> </a></td></tr>    <tr><td align="left">Linux内核官网</td><td align="left"><a href="https://www.kernel.org/" target="_blank">The Linux Kernel Archives <i class="fa fa-external-link-alt"></i> </a></td></tr>    <tr><td align="left">BusyBox官网</td><td align="left"><a href="https://busybox.net/" target="_blank">BusyBox <i class="fa fa-external-link-alt"></i> </a></td></tr></table>
              </div>
            </details>

<details class="folding-tag" blue><summary> 点击查看相关文件下载 </summary>
              <div class='content'>
              <table>    <tr><td align="center">文件</td><td align="center">下载链接</td></tr>    <tr><td align="left">roofs.rar</td><td align="left"><a href="https://wwz.lanzouy.com/i76Yz09nhakf" target="_blank">根文件系统(通过nfs共享给开发板的时候用) <i class="fa fa-external-link-alt"></i> </a></td></tr></table>
              </div>
            </details>



<h1 id="一、文件准备"><a href="#一、文件准备" class="headerlink" title="一、文件准备"></a><font size=3>一、文件准备</font></h1><h2 id="1-linux内核源码"><a href="#1-linux内核源码" class="headerlink" title="1. linux内核源码"></a><font size=3>1. <code>linux</code>内核源码</font></h2><h3 id="1-1-源码获取途径"><a href="#1-1-源码获取途径" class="headerlink" title="1.1 源码获取途径"></a><font size=3>1.1 源码获取途径</font></h3><p>关于<code>linux</code>内核的官方源码我们可以从这里获取：<a target="_blank" rel="noopener" href="https://mirrors.edge.kernel.org/pub/linux/kernel/">Index of &#x2F;pub&#x2F;linux&#x2F;kernel&#x2F;  <i class="fa fa-external-link-alt"></i></a></p>
<h3 id="1-2-获取源码文件"><a href="#1-2-获取源码文件" class="headerlink" title="1.2 获取源码文件"></a><font size=3>1.2 获取源码文件</font></h3><p>我下载的是<code>linux-3.14.tar.xz</code>这个压缩包并将其存放于<code>ubuntu</code>下的共享文件夹下，路径为：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">/mnt/hgfs/Sharedfiles/test</span><br></pre></td></tr></table></figure>

<h3 id="1-3-拷贝解压"><a href="#1-3-拷贝解压" class="headerlink" title="1.3 拷贝解压"></a><font size=3>1.3 拷贝解压</font></h3><p>然后我们可以将这个源码文件拷贝解压到<code>ubuntu</code>中，方便后边编译，我们可以在终端执行以下命令：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">cp /mnt/hgfs/Sharedfiles/test/linux-3.14.tar.xz ~/6temp/    # 拷贝压缩包</span><br><span class="line">cd ~/6temp/</span><br><span class="line">tar -xvf linux-3.14.tar.xz                                  # 解压</span><br></pre></td></tr></table></figure>

<p>然后我们可以得到下边这些文件（通过<code>ls</code>命令查看）：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV09-uboot%E4%B8%8Elinux/LV09-03-linux-02-linux%E5%86%85%E6%A0%B8%E7%A7%BB%E6%A4%8D/img/image-20220821125151346.png" alt="image-20220821125151346" style="zoom:50%;" />

<details class="folding-tag" blue><summary> 点击查看部分文件说明 </summary>
              <div class='content'>
              <ul><li><strong>平台相关</strong></li></ul><p>即与<code>CPU</code>架构或开发板硬件相关的源码，硬件的改动对应的代码也需要进行修改。</p><table>    <tr><td align="left">arch </td><td align="left">与CPU架构相关的源代码</td></tr></table><ul><li><strong>平台无关</strong></li></ul><table>    <tr><td align="left">block</td><td align="left">磁盘设备的支持，就是块设备相关目录</td></tr>    <tr><td align="left">crypto</td><td align="left">加密相关</td></tr>    <tr><td align="left">drivers</td><td align="left">设备驱动</td></tr>    <tr><td align="left">Documentation </td><td align="left">帮助文档</td></tr>    <tr><td align="left">firmware</td><td align="left">固件</td></tr>    <tr><td align="left">fs</td><td align="left">文件系统</td></tr>    <tr><td align="left">include</td><td align="left">头文件</td></tr>    <tr><td align="left">init</td><td align="left">内核初始化</td></tr>    <tr><td align="left">ipc</td><td align="left">进程间通信</td></tr>    <tr><td align="left">kernel</td><td align="left">内核核心调度机制等</td></tr>    <tr><td align="left">lib</td><td align="left">库相关目录</td></tr>    <tr><td align="left">mm</td><td align="left">内存管理</td></tr>    <tr><td align="left">net</td><td align="left">网络协议</td></tr>    <tr><td align="left">samples</td><td align="left">例程</td></tr>    <tr><td align="left">scripts</td><td align="left">工具、脚本等</td></tr>    <tr><td align="left">security</td><td align="left">安全</td></tr>    <tr><td align="left">sound</td><td align="left">音频处理</td></tr>    <tr><td align="left">tools</td><td align="left">工具</td></tr>    <tr><td align="left">usr</td><td align="left">打包与压缩，与initramfs相关的目录，用于生成initramfs</td></tr>    <tr><td align="left">virt</td><td align="left">提供虚拟机技术(KVM)</td></tr></table><p>还有一些其他的文件，这里就不再写了。</p>
              </div>
            </details>

<h2 id="2-Busybox源码"><a href="#2-Busybox源码" class="headerlink" title="2. Busybox源码"></a><font size=3>2. <code>Busybox</code>源码</font></h2><h3 id="2-1-源码获取途径"><a href="#2-1-源码获取途径" class="headerlink" title="2.1 源码获取途径"></a><font size=3>2.1 源码获取途径</font></h3><p>我们可以从这里获取<code>Busybox</code>的源码：<a target="_blank" rel="noopener" href="https://busybox.net/downloads/">Index of &#x2F;downloads (busybox.net)  <i class="fa fa-external-link-alt"></i></a></p>
<h3 id="2-2-获取源码文件"><a href="#2-2-获取源码文件" class="headerlink" title="2.2 获取源码文件"></a><font size=3>2.2 获取源码文件</font></h3><p>我下载的是<code>busybox-1.22.1.tar.bz2</code>这个压缩包并将其存放于<code>ubuntu</code>下的共享文件夹下，路径为：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">/mnt/hgfs/Sharedfiles/test</span><br></pre></td></tr></table></figure>

<h3 id="2-3-拷贝解压"><a href="#2-3-拷贝解压" class="headerlink" title="2.3 拷贝解压"></a><font size=3>2.3 拷贝解压</font></h3><p>然后我们可以将这个源码文件拷贝解压到<code>ubuntu</code>中，方便后边编译，我们可以在终端执行以下命令：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">cp /mnt/hgfs/Sharedfiles/test/busybox-1.22.1.tar.bz2 ~/6temp/    # 拷贝压缩包</span><br><span class="line">cd ~/6temp/</span><br><span class="line">tar -xvf busybox-1.22.1.tar.bz2                                  # 解压</span><br></pre></td></tr></table></figure>

<p>然后我们可以得到下边这些文件（通过<code>ls</code>命令查看）：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV09-uboot%E4%B8%8Elinux/LV09-03-linux-02-linux%E5%86%85%E6%A0%B8%E7%A7%BB%E6%A4%8D/img/image-20220821125437145.png" alt="image-20220821125437145" style="zoom:50%;" />

<h2 id="3-rootfs"><a href="#3-rootfs" class="headerlink" title="3. rootfs"></a><font size=3>3. <code>rootfs</code></font></h2><h3 id="3-1-文件获取"><a href="#3-1-文件获取" class="headerlink" title="3.1 文件获取"></a><font size=3>3.1 文件获取</font></h3><p>这里是直接制作好了的根文件系统相关文件有些文件可以直接从这里边拷贝，我们直接从这里下载并解压：<a target="_blank" rel="noopener" href="https://wwz.lanzouy.com/i76Yz09nhakf">根文件系统(roofs.rar，通过nfs共享给开发板的时候用)  <i class="fa fa-external-link-alt"></i></a>  </p>
<p>下载完毕后，存放于<code>ubuntu</code>的共享文件夹中：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">/mnt/hgfs/Sharedfiles/test</span><br></pre></td></tr></table></figure>

<p>我们可直接在<code>windows</code>下将压缩文件解压，我们将得到一个名为<code>rootfs.tar.bz2</code>的压缩包</p>
<h3 id="3-2-拷贝解压"><a href="#3-2-拷贝解压" class="headerlink" title="3.2 拷贝解压"></a><font size=3>3.2 拷贝解压</font></h3><p>然后我们可以将这个文件拷贝解压到<code>ubuntu</code>中，方便后边编译，我们可以在终端执行以下命令：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">cp /mnt/hgfs/Sharedfiles/test/roofs/rootfs.tar.bz2 ~/6temp/    # 拷贝压缩包</span><br><span class="line">cd ~/6temp/</span><br><span class="line">mkdir ~/6temp/rootfs</span><br><span class="line">tar -xvf rootfs.tar.bz2 -C rootfs                              # 解压</span><br></pre></td></tr></table></figure>

<p>然后我们可以得到下边这些文件（通过<code>ls</code>命令查看）：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV09-uboot%E4%B8%8Elinux/LV09-03-linux-02-linux%E5%86%85%E6%A0%B8%E7%A7%BB%E6%A4%8D/img/image-20220821130122961.png" alt="image-20220821130122961" style="zoom:50%;" />

<details class="folding-tag" blue><summary> 点击查看部分目录说明 </summary>
              <div class='content'>
              <table>    <tr><td align="left">bin</td><td align="left">shell命令(elf格式)(通过busybox编译生成)</td></tr>    <tr><td align="left">dev</td><td align="left">设备文件(内核启动后会将设备信息写入该目录)</td></tr>    <tr><td align="left">etc</td><td align="left">内核配置文件</td></tr>    <tr><td align="left">lib</td><td align="left">共享库(elf格式)(从交叉编译工具链中获取)</td></tr>    <tr><td align="left">linuxrc</td><td align="left">内核运行的第一个应用程序(通过busybox编译生成)</td></tr>    <tr><td align="left">mnt</td><td align="left">挂载目录(非必要)</td></tr>    <tr><td align="left">proc</td><td align="left">进程相关文件(内核启动后会将进程信息写入该目录)</td></tr>    <tr><td align="left">root</td><td align="left">超级用户家目录(非必要)</td></tr>    <tr><td align="left">sbin</td><td align="left">系统管理shell命令(elf格式)(通过busybox编译生成)</td></tr>    <tr><td align="left">sys</td><td align="left">驱动相关文件(内核启动后会将驱动信息写入该目录)</td></tr>    <tr><td align="left">usr</td><td align="left">shell命令(elf格式)(通过busybox编译生成)</td></tr></table>
              </div>
            </details>

<h1 id="二、Linux内核移植"><a href="#二、Linux内核移植" class="headerlink" title="二、Linux内核移植"></a><font size=3>二、<code>Linux</code>内核移植</font></h1><p>首先我们要进入<code>Linux</code>源码目录，后边所有的命令都在源码的顶层目录下进行：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cd ~/6temp/linux-3.14/</span><br></pre></td></tr></table></figure>

<h2 id="1-指定交叉编译工具"><a href="#1-指定交叉编译工具" class="headerlink" title="1. 指定交叉编译工具"></a><font size=3>1. 指定交叉编译工具</font></h2><p><code>linux</code>内核源码并不知道我们使用的处理器架构及交叉编译工具是什么，这里我们需要自己在<code>Makefile</code>中指定，我们通过下边的命令打开顶层<code>Makefile</code>文件：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vim Makefile</span><br></pre></td></tr></table></figure>

<p>找到下边的语句（这个<code>3.14</code>版本的话应该是在<code>198</code>行）：</p>
<figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">ARCH            ?= <span class="variable">$(SUBARCH)</span></span><br><span class="line">CROSS_COMPILE   ?= $(CONFIG_CROSS_COMPILE:<span class="string">&quot;%&quot;</span>=%)</span><br></pre></td></tr></table></figure>

<p>将其修改为：</p>
<figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">ARCH            ?= arm</span><br><span class="line">CROSS_COMPILE   ?= arm-none-linux-gnueabi-</span><br></pre></td></tr></table></figure>

<p>【注意】<code>arm-none-linux-gnueabi-</code>后边不要有多余的空格。</p>
<h2 id="2-linux内核编译"><a href="#2-linux内核编译" class="headerlink" title="2. linux内核编译"></a><font size=3>2. <code>linux</code>内核编译</font></h2><h3 id="2-1-内核配置"><a href="#2-1-内核配置" class="headerlink" title="2.1 内核配置"></a><font size=3>2.1 内核配置</font></h3><h4 id="2-1-1-配置文件"><a href="#2-1-1-配置文件" class="headerlink" title="2.1.1 配置文件"></a><font size=3>2.1.1 配置文件</font></h4><p><code>linux</code>内核源码的<code>arch/arm/configs</code>目录下下对各个厂商的<code>soc</code>都有一个默认配置文件，这个默认的配置文件命名格式为：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&lt;soc_name&gt;_defconfig</span><br></pre></td></tr></table></figure>

<p>当我们执行一个<code>make &lt;soc_name&gt;_defconfig</code>命令的时候，就会将对应的配置文件也就是<code>&lt;soc_name&gt;_defconfig</code>中的信息导入到源码顶层目录下的<code>.config</code>。配置文件中的语句有两种：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">CONFIG_xxx=y</span><br><span class="line"><span class="meta prompt_">#</span><span class="language-bash">CONFIG_xxx is not <span class="built_in">set</span></span></span><br></pre></td></tr></table></figure>

<ul>
<li><code>CONFIG_xxx=y</code>：表示内核选中了该功能，内核编译时就会将该功能对应的代码编译，内核的体积也会增大。</li>
<li><code>#CONFIG_xxx is not set</code>：表示内核没有选中该功能，内核编译时该功能对应的代码不会被编译，内核的体积也会减小。</li>
</ul>
<h4 id="2-1-2-修改配置文件"><a href="#2-1-2-修改配置文件" class="headerlink" title="2.1.2 修改配置文件"></a><font size=3>2.1.2 修改配置文件</font></h4><p>默认配置只能保证内核拥有最基本的功能，我们需要根据自己的实际需求对内核做进一步的配置，修改<code>soc</code>配置文件的话有两种方式，一种是直接修改<code>.config</code>文件或者<code>&lt;soc_name&gt;_defconfig</code>文件，但是这种方式并不推荐，因为我们修改一个配置，这个配置可能相应的依赖另外好几个配置，打开这一个配置，需要打开所有依赖的配置，但是很多时候我们并不能准确的打开所有的依赖配置；方式二就是通过图形界面来修改配置，这种方式可以直接解决依赖问题。</p>
<p>我们通过以下命令打开图形配置界面：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">make menuconfig</span><br></pre></td></tr></table></figure>

<p>【注意】<code>make menuconfig</code>本质还是修改了<code>.config</code>文件。</p>
<details class="folding-tag" blue><summary> 点击查看可能出现的问题 </summary>
              <div class='content'>
              <ul><li>问题一</li></ul><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV09-uboot%E4%B8%8Elinux/LV09-03-linux-02-linux%E5%86%85%E6%A0%B8%E7%A7%BB%E6%A4%8D/img/image-20220821210813855.png" alt="image-20220821210813855" style="zoom:50%;" /><p>这是因为我们没有安装对应的图形库，我们执行以下命令安装相应的图形库即可：</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo apt-get install libncurses5-dev</span><br></pre></td></tr></table></figure><ul><li>问题二</li></ul><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV09-uboot%E4%B8%8Elinux/LV09-03-linux-02-linux%E5%86%85%E6%A0%B8%E7%A7%BB%E6%A4%8D/img/image-20220821211016125.png" alt="image-20220821211016125" style="zoom:50%;" /><p>这是因为我们的终端太小了，拉大一点就可以了，上边提示说，必须至少有<code>19</code>行<code>80</code>列才可以。</p>
              </div>
            </details>

<p>然后我们会看到如下界面：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV09-uboot%E4%B8%8Elinux/LV09-03-linux-02-linux%E5%86%85%E6%A0%B8%E7%A7%BB%E6%A4%8D/img/image-20220821211129157.png" alt="image-20220821211129157" style="zoom:33%;" />

<p>这样便是正常打开了图形配置界面。</p>
<p>具体的操作说明，在图形界面上都有，这里主要介绍一下配置选项的两种类型：</p>
<ul>
<li><code>[]</code>有两种状态</li>
</ul>
<p>输入<code>Y</code>，显示<code>*</code>，内核中该功能被选中，相关代码会被编译进内核。</p>
<p>输入<code>N</code>，显示<code> &lt;space&gt;</code>（就是一个空格），内核中该功能不被选中，相关代码不会被编译进内核。</p>
<ul>
<li><code>&lt; &gt;</code> 有三种状态</li>
</ul>
<p>输入<code>Y</code>，显示<code>*</code>，内核中该功能被选中，相关代码会被编译进内核。</p>
<p>输入<code>N</code>，显示<code> &lt;space&gt;</code>（就是一个空格），内核中该功能不被选中，相关代码不会被编译进内核。</p>
<p>输入<code>M</code>，显示<code>M</code>，内核中该功能被选为模块（被编译为独立的模块）。</p>
<p>【注意】我们可以通过<code>&lt;space&gt;</code>（即空格按键来更改选项的状态）。</p>
<h3 id="2-2-指定使用的处理器"><a href="#2-2-指定使用的处理器" class="headerlink" title="2.2 指定使用的处理器"></a><font size=3>2.2 指定使用的处理器</font></h3><p>和<code>uboot</code>一样，在编译<code>Linux</code>内核之前要先配置<code>Linux</code>内核。每个板子都有其对应的默认配置文件，这些默认配置文件保存在 <code>arch/arm/configs</code>目录中。</p>
<p>导入当前处理器的默认配置的<code>make</code>命令格式为：</p>
  <figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">make &lt;soc_name&gt;_defconfig</span><br></pre></td></tr></table></figure>

<p>例如，我们现在导入<code>exynos_defconfig</code></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">make exynos_defconfig</span><br></pre></td></tr></table></figure>

<p>然后便会有以下提示信息：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV09-uboot%E4%B8%8Elinux/LV09-03-linux-02-linux%E5%86%85%E6%A0%B8%E7%A7%BB%E6%A4%8D/img/image-20220821144829754.png" alt="image-20220821144829754" style="zoom:33%;" />

<p>额，并未做任何修改的<code>linux</code>在配置的时候不知道这里为啥有一个警告，不过似乎对后边并没有什么影响。</p>
<h3 id="2-3-编译内核"><a href="#2-3-编译内核" class="headerlink" title="2.3 编译内核"></a><font size=3>2.3 编译内核</font></h3><p>接下来我们就可以编译<code>linux</code>内核了，我们在终端执行以下命令：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">make uImage -j4 # 4 核同时进行编译，会快那么一点点</span><br></pre></td></tr></table></figure>

<p>【注意】这个命令用于编译内核（编译选为<code>*</code>的选项到内核）。</p>
<details class="folding-tag" blue><summary> 点击查看可能出现的问题 </summary>
              <div class='content'>
              <p>要是第一次在<code>ubuntu</code>中编译<code>linux</code>内核的话，不出意外应该会报以下错误：</p><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV09-uboot%E4%B8%8Elinux/LV09-03-linux-02-linux%E5%86%85%E6%A0%B8%E7%A7%BB%E6%A4%8D/img/image-20220821145235696.png" alt="image-20220821145235696" style="zoom: 50%;" /><p>这里会提示少一个<code>mkimage</code>命令，该命令可在<code>uboot</code>源码中<code>u-boot-2013.01/tools/</code>目录下获取（注意必须是编译后的<code>uboot</code>）。</p><ul><li>我们将这个工具拷贝到我们的<code>ubuntu</code>中</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo cp ~/5linux/u-boot-2013.01/tools/mkimage /usr/bin/</span><br></pre></td></tr></table></figure><ul><li>添加可执行权限</li></ul><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo chmod 777 /usr/bin/mkimage</span><br></pre></td></tr></table></figure><p>然后回到<code>linux</code>源码的顶层目录下重新编译即可。</p>
              </div>
            </details>

<p>要是编译成功的话会有以下信息：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV09-uboot%E4%B8%8Elinux/LV09-03-linux-02-linux%E5%86%85%E6%A0%B8%E7%A7%BB%E6%A4%8D/img/image-20220821145924539.png" alt="image-20220821145924539" style="zoom:50%;" />

<h3 id="2-4-编译内核模块"><a href="#2-4-编译内核模块" class="headerlink" title="2.4 编译内核模块"></a><font size=3>2.4 编译内核模块</font></h3><p>我们在终端执行以下命令：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">make modules -j4</span><br></pre></td></tr></table></figure>

<p>【注意】这个命令用于编译内核模块（（编译选为<code>M</code>的选项为独立模块）。</p>
<p>例如，我们将<code>DM9000 support</code>配置更改为<code>M</code>状态，该选项位于：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">Device Drivers  ---&gt;</span><br><span class="line">     [*] Network device support  ---&gt; </span><br><span class="line">        [*]   Ethernet driver support  ---&gt;</span><br><span class="line">            &lt;M&gt;   DM9000 support </span><br></pre></td></tr></table></figure>

<p>我们将其选为<code>M</code>状态，然后执行上边的内核模块编译命令，然后我们进入下边的目录下：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">drivers/net/ethernet/davicom</span><br></pre></td></tr></table></figure>

<p>会发现生成了<code>dm9000.ko</code>文件，这个文件就是<code>kernel object</code>文件（内核模块），该文件作用是把内核的部分功能移动到内核外边，需要的时候插入内核，不需要时卸载。</p>
<h2 id="3-设备树编译"><a href="#3-设备树编译" class="headerlink" title="3. 设备树编译"></a><font size=3>3. 设备树编译</font></h2><h3 id="3-1-添加设备树源码文件"><a href="#3-1-添加设备树源码文件" class="headerlink" title="3.1 添加设备树源码文件"></a><font size=3>3.1 添加设备树源码文件</font></h3><p>在我们下载的<code>linux</code>内核源码中并没有我们使用的<code>fs4412</code>开发板平台的设备树文件，这里我们从源码支持的平台中找一个硬<br>件与这个开发板最类似的，在其基础上进行修改，这里我们参考的是<code>samsung</code>公司的<code>origen</code>，拷贝<code>origen</code>的设备树并将其重命名。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cp arch/arm/boot/dts/exynos4412-origen.dts arch/arm/boot/dts/exynos4412-fs4412.dts</span><br></pre></td></tr></table></figure>

<h3 id="3-2-修改相应Makefile"><a href="#3-2-修改相应Makefile" class="headerlink" title="3.2 修改相应Makefile"></a><font size=3>3.2 修改相应<code>Makefile</code></font></h3><ul>
<li><code>arch/arm/boot/dts/Makefile</code></li>
</ul>
<p>修改相应的<code>makefile</code>文件，使我们添加的设备树源码文件可以参与编译。我们打开相应的<code>Makefile</code>文件，然后找到以下语句：</p>
<figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">exynos4412-origen.dtb \</span><br></pre></td></tr></table></figure>

<p>在该语句后添加如下内容：</p>
<figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">exynos4412-fs4412.dtb \</span><br></pre></td></tr></table></figure>

<h3 id="3-3-编译设备树"><a href="#3-3-编译设备树" class="headerlink" title="3.3 编译设备树"></a><font size=3>3.3 编译设备树</font></h3><p>我们回到<code>linux</code>内核源码顶层目录下，执行以下命令：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">make dtbs -j4</span><br></pre></td></tr></table></figure>

<p>【注意】该命令会将设备树源文件<code>dts</code>编译为二进制文件<code>dtb</code>。</p>
<p>显示如下信息表示编译成功，即在<code>arch/arm/boot/dts/</code>目录下生成了<code>exynos4412-fs4412.dtb</code>。</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV09-uboot%E4%B8%8Elinux/LV09-03-linux-02-linux%E5%86%85%E6%A0%B8%E7%A7%BB%E6%A4%8D/img/image-20220821151028001.png" alt="image-20220821151028001" style="zoom:50%;" />



<h2 id="4-内核启动测试"><a href="#4-内核启动测试" class="headerlink" title="4. 内核启动测试"></a><font size=3>4. 内核启动测试</font></h2><p>上边我们已经编译好了内核和设备树，下边我们就测试一下我们自己编译的内核能否启动。之前的时候在学习<code>linux</code>内核加载的时候，我们在<code>ubuntu</code>的<code>~/3tftp/fs4412</code>和<code>~/4nfs</code>中已经放入了相关的所有文件：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV09-uboot%E4%B8%8Elinux/LV09-03-linux-02-linux%E5%86%85%E6%A0%B8%E7%A7%BB%E6%A4%8D/img/image-20220821151631835.png" alt="image-20220821151631835" style="zoom:50%;" />

<ul>
<li>拷贝相关文件</li>
</ul>
<p>我们将我们自己编译得到的<code>uImage</code>文件和<code>exynos4412-fs4412.dtb</code>拷贝到<code>~/3tftp/fs4412</code>中，根文件系统的话还是先使用之前的。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">cp arch/arm/boot/uImage ~/3tftp/fs4412/</span><br><span class="line">cp arch/arm/boot/dts/exynos4412-fs4412.dtb ~/3tftp/fs4412/</span><br></pre></td></tr></table></figure>

<ul>
<li>设置<code>uboot</code>变量</li>
</ul>
<p>这一步我们之前应该设置过了，我们从<code>eMMC</code>启动<code>uboot</code>，从<code>tftp</code>下载<code>linux</code>内核和设备树文件，从<code>nfs</code>挂载根文件系统，相应的两个参数设置如下：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">fs4412 # print bootcmd</span><br><span class="line">bootcmd=tftp 0x41000000 /fs4412/uImage;tftp 0x42000000 /fs4412/exynos4412-fs4412.dtb;bootm 0x41000000 - 0x42000000</span><br><span class="line">fs4412 # print bootargs</span><br><span class="line">bootargs=root=/dev/nfs nfsroot=192.168.10.101:/home/hk/4nfs/rootfs rw console=ttySAC2,115200 init=/linuxrc ip=192.168.10.102</span><br></pre></td></tr></table></figure>

<ul>
<li>重启相关服务</li>
</ul>
<p>我们重启一下<code>tftp</code>和<code>nfs</code>服务，在<code>ubuntu</code>终端执行：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">sudo service tftpd-hpa restart</span><br><span class="line">sudo service nfs-kernel-server restart</span><br></pre></td></tr></table></figure>

<ul>
<li>重启开发板</li>
</ul>
<p>最后就是重启开发板，观察现象了。这样的话其实我们会发现内核可以正常启动了，但是到后边就崩溃卡死了：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV09-uboot%E4%B8%8Elinux/LV09-03-linux-02-linux%E5%86%85%E6%A0%B8%E7%A7%BB%E6%A4%8D/img/image-20220821152715000.png" alt="image-20220821152715000" style="zoom: 50%;" />

<p>原因在于我们在该实验中什么都没有配置，而其他功能都保持默认选项，内核默认配置中没选配我们使用的网卡驱动、<code>nfs</code> 等功能，所以在挂载根文件系统时导致内核崩溃，所以后续我们还需要配置网卡驱动、<code>nfs</code> 等。不过这一部分的主要目的就是实现内核的启动，能出现这些提示已经表明我们的目的达到了。</p>
<h1 id="三、基本驱动移植"><a href="#三、基本驱动移植" class="headerlink" title="三、基本驱动移植"></a><font size=3>三、基本驱动移植</font></h1><h2 id="1-串口驱动"><a href="#1-串口驱动" class="headerlink" title="1. 串口驱动"></a><font size=3>1. 串口驱动</font></h2><p>串口驱动的移植较为简单，我们只需要在<code>linux</code>内核配置图形界面打开相应的配置即可。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">System Type  ---&gt;</span><br><span class="line">    (2) S3C UART to use for low-level messages</span><br></pre></td></tr></table></figure>

<p>我们将将<code>System Type</code>菜单下的<code>S3C UART to use for low-level messages</code>修改为<code>2</code>（即使用<code>UART2</code>），初始的时候是<code>3</code>。</p>
<h2 id="2-网卡驱动"><a href="#2-网卡驱动" class="headerlink" title="2. 网卡驱动"></a><font size=3>2. 网卡驱动</font></h2><h3 id="2-1-修改内核配置"><a href="#2-1-修改内核配置" class="headerlink" title="2.1 修改内核配置"></a><font size=3>2.1 修改内核配置</font></h3><p>我们执行以下命令打开图形配置界面：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">make menuconfig</span><br></pre></td></tr></table></figure>

<ul>
<li>给内核选配<code>DM9000</code> 网卡驱动，然后选择<code>Save</code>保存</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">Device Drivers  ---&gt;</span><br><span class="line">    [*] Network device support  ---&gt; </span><br><span class="line">        [*]   Ethernet driver support  ---&gt;</span><br><span class="line">            &lt;*&gt;   DM9000 support</span><br></pre></td></tr></table></figure>

<ul>
<li>选配<code>TCP</code> 相关的网络协议（部分功能默认已经选配），然后选择<code>Save</code>保存</li>
</ul>
<p>因为内核要使用<code>NFS</code>去挂载根文件系统，而<code>NFS</code>是基于<code>TCP</code> 协议实现的，所以这里需要配置一下<code>TCP</code>相关网络协议：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">[*] Networking support  ---&gt; </span><br><span class="line">          Networking options  ---&gt;</span><br><span class="line">              &lt;*&gt; Packet socket</span><br><span class="line">              &lt;*&gt; Unix domain sockets</span><br><span class="line">              [*] TCP/IP networking</span><br><span class="line">              [*]   IP: kernel level autoconfiguration</span><br></pre></td></tr></table></figure>

<ul>
<li>选配<code>NFS</code>客户端及相关功能</li>
</ul>
<p>因为内核要使用<code>NFS</code>去挂载根文件系统，所以需要给内核选配<code>NFS</code>客户端的相关功能：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"> File systems  ---&gt; </span><br><span class="line">     [*] Network File Systems  ---&gt; </span><br><span class="line">         &lt;*&gt;   NFS client support</span><br><span class="line">         &lt;*&gt;     NFS client support for NFS version 2 (NEW)</span><br><span class="line">&lt;*&gt;     NFS client support for NFS version 3 (NEW)</span><br><span class="line">[*]       NFS client support for the NFSv3 ACL protocol extension</span><br><span class="line">[*]   Root file system on NFS </span><br></pre></td></tr></table></figure>

<p>设置完成后通过方向键选择<code>Save</code>保存即可，然后选择<code>Exit</code>退出该配置界面。</p>
<h3 id="2-2-修改设备树"><a href="#2-2-修改设备树" class="headerlink" title="2.2 修改设备树"></a><font size=3>2.2 修改设备树</font></h3><ul>
<li><code>arch/arm/boot/dts/exynos4412-fs4412.dts</code></li>
</ul>
<p>接下来我们需要在设备树中添加网卡的硬件信息，我们打开文件<code>exynos4412-fs4412.dts</code>，在文件的末尾处最后一个花括号之前添加以下内容（即要写在根节点之内）：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">srom-cs1@<span class="number">5000000</span> &#123;</span><br><span class="line">	compatible = <span class="string">&quot;simple-bus&quot;</span>;</span><br><span class="line">	<span class="meta">#address-cells = <span class="string">&lt;1&gt;</span>;</span></span><br><span class="line">	<span class="meta">#size-cells = <span class="string">&lt;1&gt;</span>;</span></span><br><span class="line">	reg = &lt;<span class="number">0x5000000</span> <span class="number">0x1000000</span>&gt;;</span><br><span class="line">	ranges;</span><br><span class="line">	ethernet@<span class="number">5000000</span> &#123;</span><br><span class="line">		compatible = <span class="string">&quot;davicom,dm9000&quot;</span>;</span><br><span class="line">		reg = &lt;<span class="number">0x5000000</span> <span class="number">0x2</span> <span class="number">0x5000004</span> <span class="number">0x2</span>&gt;;</span><br><span class="line">		interrupt-parent = &lt;&amp;gpx0&gt;;</span><br><span class="line">		interrupts = &lt;<span class="number">6</span> <span class="number">4</span>&gt;;</span><br><span class="line">		davicom,no-eeprom;</span><br><span class="line">		mac-address = [<span class="number">00</span> <span class="number">0</span>a <span class="number">2</span>d a6 <span class="number">55</span> a2];</span><br><span class="line">	&#125;;</span><br><span class="line">&#125;;</span><br></pre></td></tr></table></figure>

<h3 id="2-3-修改时钟配置"><a href="#2-3-修改时钟配置" class="headerlink" title="2.3 修改时钟配置"></a><font size=3>2.3 修改时钟配置</font></h3><ul>
<li><code>drivers/clk/clk.c</code></li>
</ul>
<p>我们需要忽略一些无关的时钟，找到以下语句：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">static</span> <span class="type">bool</span> clk_ignore_unused;</span><br></pre></td></tr></table></figure>

<p>将其修改为以下内容：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">static</span> <span class="type">bool</span> clk_ignore_unused=<span class="literal">true</span>;</span><br></pre></td></tr></table></figure>

<h3 id="2-4-修改eMMC配置"><a href="#2-4-修改eMMC配置" class="headerlink" title="2.4 修改eMMC配置"></a><font size=3>2.4 修改<code>eMMC</code>配置</font></h3><ul>
<li><code>drivers/mmc/core/mmc.c</code></li>
</ul>
<p>我们需要找到以下语句：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span> (card-&gt;ext_csd.rev &gt; <span class="number">7</span>) &#123;</span><br><span class="line">	pr_err(<span class="string">&quot;%s: unrecognised EXT_CSD revision %d\n&quot;</span>,</span><br><span class="line">		mmc_hostname(card-&gt;host), card-&gt;ext_csd.rev);</span><br><span class="line">	err = -EINVAL;</span><br><span class="line">	<span class="keyword">goto</span> out;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>将其修改为以下内容：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">if</span> 0</span></span><br><span class="line"><span class="keyword">if</span> (card-&gt;ext_csd.rev &gt; <span class="number">7</span>)&#123;</span><br><span class="line"><span class="meta">#<span class="keyword">else</span></span></span><br><span class="line"><span class="keyword">if</span> (card-&gt;ext_csd.rev &gt; <span class="number">8</span>)&#123;</span><br><span class="line"><span class="meta">#<span class="keyword">endif</span></span></span><br><span class="line">	pr_err(<span class="string">&quot;%s: unrecognised EXT_CSD revision %d\n&quot;</span>,</span><br><span class="line">		mmc_hostname(card-&gt;host), card-&gt;ext_csd.rev);</span><br><span class="line">	err = -EINVAL;</span><br><span class="line">	<span class="keyword">goto</span> out;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h2 id="3-编译内核和设备树"><a href="#3-编译内核和设备树" class="headerlink" title="3. 编译内核和设备树"></a><font size=3>3. 编译内核和设备树</font></h2><p>上边我们已经移植好了串口和网卡驱动，然后就是重新编译内核和设备树啦，我们在终端执行以下命令：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">make uImage -j4</span><br><span class="line">make dtbs -j4</span><br></pre></td></tr></table></figure>

<h2 id="4-内核启动测试-1"><a href="#4-内核启动测试-1" class="headerlink" title="4. 内核启动测试"></a><font size=3>4. 内核启动测试</font></h2><ul>
<li>拷贝相关文件</li>
</ul>
<p>我们将我们自己编译得到的<code>uImage</code>文件和<code>exynos4412-fs4412.dtb</code>拷贝到<code>~/3tftp/fs4412</code>中，根文件系统的话还是先使用之前的。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">cp arch/arm/boot/uImage ~/3tftp/fs4412/</span><br><span class="line">cp arch/arm/boot/dts/exynos4412-fs4412.dtb ~/3tftp/fs4412/</span><br></pre></td></tr></table></figure>

<ul>
<li>设置<code>uboot</code>变量</li>
</ul>
<p>这一步我们之前应该设置过了，我们从<code>eMMC</code>启动<code>uboot</code>，从<code>tftp</code>下载<code>linux</code>内核和设备树文件，从<code>nfs</code>挂载根文件系统，相应的两个参数设置如下：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">fs4412 # print bootcmd</span><br><span class="line">bootcmd=tftp 0x41000000 /fs4412/uImage;tftp 0x42000000 /fs4412/exynos4412-fs4412.dtb;bootm 0x41000000 - 0x42000000</span><br><span class="line">fs4412 # print bootargs</span><br><span class="line">bootargs=root=/dev/nfs nfsroot=192.168.10.101:/home/hk/4nfs/rootfs rw console=ttySAC2,115200 init=/linuxrc ip=192.168.10.102</span><br></pre></td></tr></table></figure>

<ul>
<li>重启相关服务</li>
</ul>
<p>我们重启一下<code>tftp</code>和<code>nfs</code>服务，在<code>ubuntu</code>终端执行：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">sudo service tftpd-hpa restart</span><br><span class="line">sudo service nfs-kernel-server restart</span><br></pre></td></tr></table></figure>

<ul>
<li>重启开发板</li>
</ul>
<p>最后就是重启开发板，观察现象了，若成功挂载文件系统，则说明我们已经成功配置了网卡。</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV09-uboot%E4%B8%8Elinux/LV09-03-linux-02-linux%E5%86%85%E6%A0%B8%E7%A7%BB%E6%A4%8D/img/image-20220822120944803.png" alt="image-20220822120944803" style="zoom:50%;" />

<h1 id="四、根文件系统移植"><a href="#四、根文件系统移植" class="headerlink" title="四、根文件系统移植"></a><font size=3>四、根文件系统移植</font></h1><p>根文件系统移植我们主要是使用<code>Busybox</code>来进行根文件系统的制作，前边我们已经准备好了相关的文件并解压了，我们进入<code>Busybox</code>源码的顶层目录：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cd ~/6temp/busybox-1.22.1/</span><br></pre></td></tr></table></figure>

<h2 id="1-配置busybox"><a href="#1-配置busybox" class="headerlink" title="1. 配置busybox"></a><font size=3>1. 配置<code>busybox</code></font></h2><p><code>busybox</code>具有和<code>linux</code>内核类似的图形配置界面，我们可以通过下边的命令进入图形配置界面：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">make menuconfig</span><br></pre></td></tr></table></figure>

<p>配置界面如下：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV09-uboot%E4%B8%8Elinux/LV09-03-linux-02-linux%E5%86%85%E6%A0%B8%E7%A7%BB%E6%A4%8D/img/image-20220822143645370.png" alt="image-20220822143645370" style="zoom:33%;" />

<p>我们在进行根文件系统制作的时候需要先配置一下<code>busybox</code>，配置如下信息即可：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">Busybox Settings  ---&gt;</span><br><span class="line">        Build Options  ---&gt;</span><br><span class="line">            [*] Build BusyBox as a static binary (no shared libs)</span><br><span class="line">            [ ] Build with Large File Support (for accessing files &gt; 2 GB)</span><br><span class="line">            (arm-none-linux-gnueabi-) Cross Compiler prefix </span><br></pre></td></tr></table></figure>

<p>配置完成后通过方向键选择<code>Exit</code>退出，并保存配置信息。</p>
<h2 id="2-编译busybox"><a href="#2-编译busybox" class="headerlink" title="2. 编译busybox"></a><font size=3>2. 编译<code>busybox</code></font></h2><p>上一步配置完成就可以开始编译<code>busybox</code>了，我们可以执行如下命令：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">make</span><br></pre></td></tr></table></figure>

<p>这个比较简单，只需要一个<code>make</code>命令就可以开始编译了，编译完成后，会在源码的顶层目录下生成一个<code>busybox</code>文件。</p>
<h2 id="3-安装busybox"><a href="#3-安装busybox" class="headerlink" title="3. 安装busybox"></a><font size=3>3. 安装<code>busybox</code></font></h2><p>上一步只是进行了编译，我们还需要安装<code>busybox</code>，我们在终端执行：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">make install</span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">其实我们也可以直接指定安装的目录，避免后边拷贝相关文件的麻烦</span></span><br><span class="line">make install CONFIG_PREFIX=/home/hk/4nfs/rootfs</span><br></pre></td></tr></table></figure>

<p>安装完成后会有如下提示信息：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV09-uboot%E4%B8%8Elinux/LV09-03-linux-02-linux%E5%86%85%E6%A0%B8%E7%A7%BB%E6%A4%8D/img/image-20220822144449480.png" alt="image-20220822144449480" style="zoom:45%;" />

<p>若未指定安装的目录，我们会发现在<code>busybox</code>源码顶层目录下会生成一个<code>_install</code>目录，我们看一下这个目录中都有什么：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ls _install -ah</span><br></pre></td></tr></table></figure>

<p>我们会发现有如下文件：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV09-uboot%E4%B8%8Elinux/LV09-03-linux-02-linux%E5%86%85%E6%A0%B8%E7%A7%BB%E6%A4%8D/img/image-20220822144724519.png" alt="image-20220822144724519" style="zoom:50%;" />

<p>这里边就是我们所需要的根文件系统，包含了根文件系统中所需的<code>shell</code>命令文件。</p>
<h2 id="4-添加lib库"><a href="#4-添加lib库" class="headerlink" title="4. 添加lib库"></a><font size=3>4. 添加<code>lib</code>库</font></h2><h3 id="4-1-拷贝lib库"><a href="#4-1-拷贝lib库" class="headerlink" title="4.1 拷贝lib库"></a><font size=3>4.1 拷贝<code>lib</code>库</font></h3><p>我们还需要将交叉编译工具链中的库文件拷贝到<code>_install</code>目录下：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cp -a  ~/2software/gcc-4.6.4/arm-arm1176jzfssf-linux-gnueabi/lib/ ./_install/</span><br></pre></td></tr></table></figure>

<p>【注意】<code>cp</code>命令要加上<code>-a</code>选项，这个选项通常在复制目录时使用，它保留链接、文件属性，并复制目录下的所有内容。因为我们要靠拷贝的文件中有几个比较特殊的库文件，例如 <code>ld-linux.so.3</code>，这些库文件是符号链接，直接拷贝的话会丢失属性，所以这里要加上<code>-a</code>选项。</p>
<h3 id="4-2-删除lib静态库"><a href="#4-2-删除lib静态库" class="headerlink" title="4.2 删除lib静态库"></a><font size=3>4.2 删除<code>lib</code>静态库</font></h3><p>我们执行以下命令删除<code>lib</code>中的静态库：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo rm ./_install/lib/*.a</span><br></pre></td></tr></table></figure>

<h3 id="4-3-删除共享库中符号表"><a href="#4-3-删除共享库中符号表" class="headerlink" title="4.3 删除共享库中符号表"></a><font size=3>4.3 删除共享库中符号表</font></h3><p>我们还需要删除剩下的共享库中的符号表，该操作需要在<code>root</code>用户中才能操作，这里需要注意我们使用的命令<code>strip</code>也需要是交叉编译器中的命令，而这个命令在<code>root</code>用户下需要带上绝对路径：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">sudo su # 切换到root用户</span><br><span class="line">/home/hk/2software/gcc-4.6.4/bin/arm-none-linux-gnueabi-strip _install/lib/*</span><br><span class="line">exit    # 退出root用户</span><br></pre></td></tr></table></figure>

<p>我们可以使用以下命令查看”瘦身”前后该目录大小的变化：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">du -mh _install/lib</span><br></pre></td></tr></table></figure>

<p>“瘦身”完成后没我们可以通过下边的命令来查看是否已经”瘦身”完毕，我们随便查看一个文件：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">file _install/lib/ld-2.17.so</span><br></pre></td></tr></table></figure>

<p>然后我们会得到如下提示信息：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">_install/lib/ld-2.17.so: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, stripped</span><br></pre></td></tr></table></figure>

<p><code>stripped</code>就表明该库已经删除了符号表，已经完成了”瘦身”。</p>
<h2 id="5-创建其他目录"><a href="#5-创建其他目录" class="headerlink" title="5. 创建其他目录"></a><font size=3>5. 创建其他目录</font></h2><p>在根文件系统中还需要创建其他文件夹，如<code>dev</code>、<code>proc</code>、<code>mnt</code>、 <code>sys</code>、 <code>tmp</code>和 <code>root</code>等：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">cd _install/</span><br><span class="line">mkdir dev mnt proc root sys tmp var</span><br></pre></td></tr></table></figure>

<p>创建完成后，我们的根文件系统目录如下图所示：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV09-uboot%E4%B8%8Elinux/LV09-03-linux-02-linux%E5%86%85%E6%A0%B8%E7%A7%BB%E6%A4%8D/img/image-20220822151946505.png" alt="image-20220822151946505" style="zoom:50%;" />

<p>我们刚才创建的几个都是空目录，其实可以发现我们还是少了一个<code>etc</code>目录，我们这里先不创建，一会先进行测试看看没有这个目录会有什么事情发生。</p>
<h2 id="6-根文件系统初步测试"><a href="#6-根文件系统初步测试" class="headerlink" title="6. 根文件系统初步测试"></a><font size=3>6. 根文件系统初步测试</font></h2><p>我们到安装了<code>busybox</code>的目录中，方便后续操作：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cd ~/6temp/busybox-1.22.1/_install/</span><br></pre></td></tr></table></figure>

<ul>
<li>删除原来的根文件系统</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo rm -rf ~/4nfs/rootfs/*</span><br></pre></td></tr></table></figure>

<ul>
<li>拷贝我们自己制作的根文件系统到相应的挂载目录</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo cp -rf ./* ~/4nfs/rootfs/</span><br></pre></td></tr></table></figure>

<ul>
<li>重启开发板</li>
</ul>
<p>注意我们使用的<code>uboot</code>参数与上边<code>linux</code>内核移植时一样，从<code>tftp</code>加载<code>linux</code>内核和设备树，从<code>nfs</code>挂载根文件系统。</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV09-uboot%E4%B8%8Elinux/LV09-03-linux-02-linux%E5%86%85%E6%A0%B8%E7%A7%BB%E6%A4%8D/img/image-20220822152625842.png" alt="image-20220822152625842" style="zoom:40%;" />

<p>从图中我们会发现，根文件系统正常挂载了，并且<code>ls</code>命令也可正常运行，但是有一个错误提示：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">can&#x27;t run &#x27;/etc/init.d/rcS&#x27;: No such file or directory</span><br></pre></td></tr></table></figure>

<p>这个错误提示其实很简单，说是无法运行“<code>/etc/init.d/rcS</code>这个文件，因为这个文件不存在。</p>
<h2 id="7-完善根文件系统"><a href="#7-完善根文件系统" class="headerlink" title="7. 完善根文件系统"></a><font size=3>7. 完善根文件系统</font></h2><h3 id="7-1-etc目录介绍"><a href="#7-1-etc目录介绍" class="headerlink" title="7.1 etc目录介绍"></a><font size=3>7.1 <code>etc</code>目录介绍</font></h3><h4 id="7-1-1-目录结构"><a href="#7-1-1-目录结构" class="headerlink" title="7.1.1 目录结构"></a><font size=3>7.1.1 目录结构</font></h4><p>刚才的错误提示就是提示我们缺少<code>/etc/init.d/rcS</code>文件，但是我们打开以前已经制作好的根文件目录<code>rootfs</code>看一下<code>etc</code>目录下都有哪些文件（前边准备文件的时候有解压过这个目录）：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">cd  ~/6temp/rootfs/etc/  # 进入 etc 目录</span><br><span class="line">tree                     # 查看该目录的结构</span><br></pre></td></tr></table></figure>

<p>然后我们会得到如下信息：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV09-uboot%E4%B8%8Elinux/LV09-03-linux-02-linux%E5%86%85%E6%A0%B8%E7%A7%BB%E6%A4%8D/img/image-20220822153229722.png" alt="image-20220822153229722" style="zoom: 50%;" />

<h4 id="7-1-2-rcS文件"><a href="#7-1-2-rcS文件" class="headerlink" title="7.1.2 rcS文件"></a><font size=3>7.1.2 <code>rcS</code>文件</font></h4><p><code>rcS</code>是个<code>shell</code>脚本，<code>Linux</code>内核启动以后需要启动一些服务，而<code>rcS</code>就是规定启动哪些文件的脚本文件。该文件应改位于<code>etc/init.d/rcS</code>文件，我们打开这个文件看一下都有什么：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vim ~/6temp/rootfs/etc/init.d/rcS</span><br></pre></td></tr></table></figure>

<p>我们会看到如下信息：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">!/bin/sh</span> </span><br><span class="line">/bin/mount -a</span><br><span class="line">echo /sbin/mdev &gt; /proc/sys/kernel/hotplug </span><br><span class="line">/sbin/mdev -s</span><br></pre></td></tr></table></figure>

<ul>
<li>第<code>1</code>行：表示这是一个<code>shell</code>脚本。</li>
<li>第<code>2</code>行：使用<code>mount</code>命令来挂载所有的文件系统，这些文件系统由文件<code>etc/fstab</code>来指定。</li>
<li>第<code>3</code>行和第<code>4</code>行：使用<code>mdev</code>来管理热插拔设备，通过这两行，<code>Linux</code>内核就可以在<code>/dev</code>目录下自动创建设备节点。关于<code>mdev</code>的详细内容可以参考 <code>busybox</code>中的<code>docs/mdev.txt</code>文档。</li>
</ul>
<p>【说明】</p>
<p>（1）这只是我们自己做的根文件系统中的<code>rcS</code>文件，这个是比较简单的，只有这么几行，但是<code>Ubuntu</code>或者其他大型<code>Linux</code>操作系统中的<code>rcS</code>文件，会更加的复杂，一般来说复杂的<code>rcS</code>文件也是借助其他工具创建的，比如 <code>buildroot</code>等。</p>
<p>（2）<code>etc/init.d/rcS</code>这个文件是需要有可执行文件才可以运行的。</p>
<h4 id="7-1-3-fstab文件"><a href="#7-1-3-fstab文件" class="headerlink" title="7.1.3 fstab文件"></a><font size=3>7.1.3 <code>fstab</code>文件</font></h4><p><code>etc/fstab</code>文件在<code>Linux</code>开机以后自动配置哪些需要自动挂载的分区，该文件中内容的格式如下：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&lt;file system&gt; &lt;mount point&gt; &lt;type&gt; &lt;options&gt; &lt;dump&gt; &lt;pass&gt;</span><br></pre></td></tr></table></figure>

<ul>
<li><code>file system</code>：要挂载的特殊的设备，也可以是块设备，比如<code>/dev/sda</code>等等。</li>
<li><code>mount point</code>：挂载点。</li>
<li><code>type</code>：文件系统类型，比如 <code>ext2</code>、 <code>ext3</code>、 <code>proc</code>、<code>romfs</code>、 <code>tmpfs</code>等等。</li>
<li><code>options</code>：挂载选项，在<code>Ubuntu</code>中输入<code>man mount</code>命令可以查看具体的选项。一般使用<code>defaults</code>，也就是默认选项，<code>defaults</code>包含了 <code>rw</code>、 <code>suid</code>、 <code>dev</code>、 <code>exec</code>、 <code>auto</code>、 <code>nouser</code>和 <code>async</code>。</li>
<li><code>dump</code>：为<code>1</code>的话表示允许备份，为<code>0</code>不备份，一般不备份，因此设置为 <code>0</code>。</li>
<li><code>pass</code>：磁盘检查设置，为<code>0</code>表示不检查。根目录<code>/</code>设置为<code>1</code>，其他的都不能设置为<code>1</code>，其他的分区从<code>2</code>开始。一般不在<code>fstab</code>中挂载根目录，因此这里一般设置为<code>0</code>。</li>
</ul>
<p>我们可以打开一个创建好的文件看一下：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vim ~/6temp/rootfs/etc/fstab</span><br></pre></td></tr></table></figure>

<p>我们会看到如下内容：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">#</span><span class="language-bash">device mount-point <span class="built_in">type</span> options dump fsck orde</span></span><br><span class="line">proc   /proc  proc  defaults  0  0</span><br><span class="line">tmpfs  /tmp   tmpfs defaults  0  0</span><br><span class="line">sysfs  /sys   sysfs defaults  0  0</span><br><span class="line">tmpfs  /dev   tmpfs defaults  0  0</span><br></pre></td></tr></table></figure>

<h4 id="7-1-4-inittab文件"><a href="#7-1-4-inittab文件" class="headerlink" title="7.1.4 inittab文件"></a><font size=3>7.1.4 <code>inittab</code>文件</font></h4><p><code>inittab</code>的详细内容可以参考<code>busybox</code>下的文件<code>examples/inittab</code>。<code>init</code>程序会读取<code>etc/inittab</code>这个文件，<code>inittab</code>由若干条指令组成。每条指令的结构都是一样的，由以<code>:</code>分隔的 4个段组成，格式如下：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&lt;id&gt;:&lt;runlevels&gt;:&lt;action&gt;:&lt;process&gt;</span><br></pre></td></tr></table></figure>

<ul>
<li><code>id</code>：每个指令的标识符，不能重复。但是对于<code>busybox</code>的<code>init</code>来说，<code>id</code>有着特殊意义。对于<code>busybox</code>而言<code>id</code>用来指定启动进程的控制<code>tty</code>，一般我们将串口或者<code>LCD</code>屏幕设置为控制<code>tty</code>。</li>
<li><code>runlevels</code>：对<code>busybox</code>来说此项完全没用，所以可以空着。</li>
<li><code>action</code>：动作，用于指定<code>process</code>可能用到的动作。</li>
</ul>
<details class="folding-tag" blue><summary> 点击查看busybox支持的动作 </summary>
              <div class='content'>
              <table>    <tr><td align="left">动作</td><td align="left">描述</td></tr>    <tr><td align="left">sysinit</td><td align="left">在系统初始化的时候 process 才会执行一次。</td></tr>    <tr><td align="left">respawn</td><td align="left">当 process 终止以后马上启动一个新的。</td></tr>    <tr><td align="left">askfirst</td><td align="left">和respawn类似，在运行 process之前在控制台上显示“Please press Enter to activate this console.”。只有用户按下 Enter 键以后才会执行 process。</td></tr>    <tr><td align="left">wait</td><td align="left">告诉init，要等待相应的进程执行完以后才能继续执行。</td></tr>    <tr><td align="left">once</td><td align="left">仅执行一次，而且不会等待 process 执行完成。</td></tr>    <tr><td align="left">restart</td><td align="left">当init重启的时候才会执行 procee。</td></tr>    <tr><td align="left">ctrlaltdel</td><td align="left">当按下ctrl+alt+del组合键才会执行 process。</td></tr>    <tr><td align="left">shutdown</td><td align="left">关机的时候执行process。</td></tr></table>
              </div>
            </details>

<ul>
<li><code>process</code>：具体的动作，比如程序、脚本或命令等。</li>
</ul>
<p>例如，我们打开一个创建好了的文件看一下：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vim ~/6temp/rootfs/etc/inittab</span><br></pre></td></tr></table></figure>

<p>我们会看到以下信息：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">::sysinit:/etc/init.d/rcS </span><br><span class="line">::askfirst:-/bin/sh</span><br><span class="line">::restart:/sbin/init </span><br><span class="line">::ctrlaltdel:/sbin/reboot</span><br></pre></td></tr></table></figure>

<ul>
<li>第<code>1</code>行，系统启动以后运行<code>/etc/init.d/rcS</code>这个脚本文件。</li>
<li>第<code>2</code>行，系统启动以后，在运行<code>process</code>之前在控制台上显示提示信息，只有用户按下<code>Enter</code>键以后才会执行<code>process</code>。</li>
<li>第<code>3</code>行，系统启动以后，重启的话运行<code>/sbin/init</code>。</li>
<li>第<code>4</code>行，按下<code>ctrl+alt+del</code>组合键的话就运行<code>/sbin/reboot</code>，也就是说<code>ctrl+alt+del</code>组合键可以用于重启系统。</li>
</ul>
<h3 id="7-2-etc目录创建"><a href="#7-2-etc目录创建" class="headerlink" title="7.2 etc目录创建"></a><font size=3>7.2 <code>etc</code>目录创建</font></h3><p>我们可以自己按照创建好的<code>etc</code>目录文件内容逐个创建文件，也可以拷贝已经做好的<code>etc</code>目录，后续再修改相关文件，以达到自己的预期效果。</p>
<ul>
<li>这里我们拷贝已经创建好的<code>etc</code>目录：</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cp -r ~/6temp/rootfs/etc ~/6temp/busybox-1.22.1/_install/</span><br></pre></td></tr></table></figure>

<ul>
<li>给<code>rcS</code>文件添加可执行权限</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo chmod +x ~/6temp/busybox-1.22.1/_install/etc/init.d/rcS</span><br></pre></td></tr></table></figure>

<h3 id="7-3-根文件系统测试"><a href="#7-3-根文件系统测试" class="headerlink" title="7.3 根文件系统测试"></a><font size=3>7.3 根文件系统测试</font></h3><ul>
<li>删除原来的根文件系统</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo rm -rf ~/4nfs/rootfs/*</span><br></pre></td></tr></table></figure>

<ul>
<li>拷贝我们自己制作的根文件系统到相应的挂载目录</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo cp -rf ~/6temp/busybox-1.22.1/_install/* ~/4nfs/rootfs/</span><br></pre></td></tr></table></figure>

<ul>
<li>重启开发板</li>
</ul>
<p>这一次我们会发现启动后没有错误提示了：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV09-uboot%E4%B8%8Elinux/LV09-03-linux-02-linux%E5%86%85%E6%A0%B8%E7%A7%BB%E6%A4%8D/img/image-20220822161009551.png" alt="image-20220822161009551" style="zoom:33%;" />

<h2 id="8-busybox中文字符支持"><a href="#8-busybox中文字符支持" class="headerlink" title="8. busybox中文字符支持"></a><font size=3>8. <code>busybox</code>中文字符支持</font></h2><p>我们是通过<code>nfs</code>挂载的根文件系统，我们可以在<code>ubuntu</code>的相关目录下创建一个中文命名的目录，例如：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">cd ~/4nfs/rootfs/</span><br><span class="line">mkdir 桌面</span><br><span class="line">ls</span><br></pre></td></tr></table></figure>

<p>然后我们会看到<code>ubuntu</code>下目录详情如下：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">bin  dev  etc  lib  linuxrc  mnt  proc  root  sbin  sys  tmp  usr  var  桌面</span><br></pre></td></tr></table></figure>

<p>然而我们到<code>SecureCRT</code>中，看一下根目录：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">[root@farsight]#</span><span class="language-bash"><span class="built_in">ls</span></span></span><br><span class="line">bin      etc      linuxrc  proc     sbin     tmp      var</span><br><span class="line">dev      lib      mnt      root     sys      usr      ??</span><br></pre></td></tr></table></figure>

<p>我们会发现并不支持中文而中中文目录显示为<code>?</code>。老版本的<code>busybox</code>是支持中文的，但是不知道从哪个版本开始<code>busybox</code>中的<code>shell</code>命令对中文输入即显示做了限制，即使内核支持中文但在<code>shell</code>下也依然无法正确显示。这个时候就需要修改<code>busybox</code>源码了。</p>
<p>我们先进入<code>busybox</code>源码顶层目录：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cd ~/6temp/busybox-1.22.1/</span><br></pre></td></tr></table></figure>

<h3 id="8-1-printable-string-c文件修改"><a href="#8-1-printable-string-c文件修改" class="headerlink" title="8.1 printable_string.c文件修改"></a><font size=3>8.1 <code>printable_string.c</code>文件修改</font></h3><p>首先我们需要修改<code>libbb/printable_string.c</code>文件，我们打开该文件后，会发现这里边只有一个<code>printable_string</code>函数，该函数中有这么几条语句：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/* 下边if出现在34行 */</span></span><br><span class="line">		<span class="keyword">if</span> (c &gt;= <span class="number">0x7f</span>)</span><br><span class="line">			<span class="keyword">break</span>;</span><br><span class="line"><span class="comment">/* 下边if出现在48行 */</span></span><br><span class="line">			<span class="keyword">if</span> (c &lt; <span class="string">&#x27; &#x27;</span> || c &gt;= <span class="number">0x7f</span>)</span><br><span class="line">				*d = <span class="string">&#x27;?&#x27;</span>;</span><br></pre></td></tr></table></figure>

<p>通过这几个语句我们知道，当字符大于<code>0X7F</code>以后就跳出去了。如果支持<code>UNICODE</code>码的话，当字符大于<code>0X7F</code>就直接输出<code>?</code>。我们将上边的两个<code>if</code>语句进行修改：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/* 下边if出现在34行（将这个if注释掉） */</span></span><br><span class="line">		<span class="comment">// if (c &gt;= 0x7f)</span></span><br><span class="line">		<span class="comment">// 	break;</span></span><br><span class="line"><span class="comment">/* 下边if出现在48行 */</span></span><br><span class="line">			<span class="comment">// if (c &lt; &#x27; &#x27; || c &gt;= 0x7f)</span></span><br><span class="line">			<span class="keyword">if</span> (c &lt; <span class="string">&#x27; &#x27;</span>)</span><br><span class="line">				*d = <span class="string">&#x27;?&#x27;</span>;</span><br></pre></td></tr></table></figure>

<p>这两处修改主要是为了禁止字符大于<code>0X7F</code>以后<code>break</code>和输出<code>?</code>。</p>
<h3 id="8-2-unicode-c文件修改"><a href="#8-2-unicode-c文件修改" class="headerlink" title="8.2 unicode.c文件修改"></a><font size=3>8.2 <code>unicode.c</code>文件修改</font></h3><p>我们打开<code>libbb/unicode.c</code>文件，然后找到<code>unicode_conv_to_printable2</code>函数，在该函数中有这么几行：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/* 下边的这个三目运算符语句出现在 1022 行*/</span></span><br><span class="line">				*d++ = (c &gt;= <span class="string">&#x27; &#x27;</span> &amp;&amp; c &lt; <span class="number">0x7f</span>) ? c : <span class="string">&#x27;?&#x27;</span>;</span><br><span class="line"><span class="comment">/* 下边的这个if 出现在 1030 行*/</span></span><br><span class="line">				<span class="keyword">if</span> (c &lt; <span class="string">&#x27; &#x27;</span> || c &gt;= <span class="number">0x7f</span>)</span><br><span class="line">					*d = <span class="string">&#x27;?&#x27;</span>;</span><br></pre></td></tr></table></figure>

<p><code>1022</code>行表示当字符大于<code>0X7F</code>以后，<code>*d++</code>就为<code>?</code>，<code>1030</code>行和<code>1031</code>行表示，当字符大于<code>0X7F</code>以后，<code>*d</code>也为<code>?</code>。我们将其修改为以下内容：</p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/* 下边的这个三目运算符语句出现在 1022 行*/</span></span><br><span class="line">				<span class="comment">// *d++ = (c &gt;= &#x27; &#x27; &amp;&amp; c &lt; 0x7f) ? c : &#x27;?&#x27;;</span></span><br><span class="line">				*d++ = (c &gt;= <span class="string">&#x27; &#x27;</span>) ? c : <span class="string">&#x27;?&#x27;</span>;</span><br><span class="line"><span class="comment">/* 下边的这个if 出现在 1030 行*/</span></span><br><span class="line">				<span class="comment">// if (c &lt; &#x27; &#x27; || c &gt;= 0x7f)</span></span><br><span class="line">				<span class="keyword">if</span> (c &lt; <span class="string">&#x27; &#x27;</span>)</span><br><span class="line">					*d = <span class="string">&#x27;?&#x27;</span>;</span><br></pre></td></tr></table></figure>

<h3 id="8-3-busybox配置"><a href="#8-3-busybox配置" class="headerlink" title="8.3 busybox配置"></a><font size=3>8.3 <code>busybox</code>配置</font></h3><p>我们执行以下命令打开<code>busybox</code>的图形配置界面：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">make menuconfig</span><br></pre></td></tr></table></figure>

<p>然后我们需要使能<code>busybox</code>的<code>unicode</code>编码以支持中文，配置路径如下：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">Busybox Settings  ---&gt;</span><br><span class="line">        General Configuration  ---&gt; </span><br><span class="line">            [*] Support Unicode</span><br><span class="line">            [*]   Check $LC_ALL, $LC_CTYPE and $LANG environment variables</span><br></pre></td></tr></table></figure>

<p>然后退出，一定要记得保存。</p>
<h3 id="8-4-重新制作根文件系统"><a href="#8-4-重新制作根文件系统" class="headerlink" title="8.4 重新制作根文件系统"></a><font size=3>8.4 重新制作根文件系统</font></h3><p>按照前边的步骤重新制作根文件系统即可。</p>
<h3 id="8-5-中文支持测试"><a href="#8-5-中文支持测试" class="headerlink" title="8.5 中文支持测试"></a><font size=3>8.5 中文支持测试</font></h3><img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/01HQ%E8%AF%BE%E7%A8%8B%E4%BD%93%E7%B3%BB/LV09-uboot%E4%B8%8Elinux/LV09-03-linux-02-linux%E5%86%85%E6%A0%B8%E7%A7%BB%E6%A4%8D/img/image-20220822165230442.png" alt="image-20220822165230442" style="zoom:50%;" />


    </div>

    
    
    

    <footer class="post-footer">




    <div>
        
            <div style="text-align:center;color: #ccc;font-size:14px;">
            ----------本文结束
            <i class="fas fa-fan fa-spin" style="color: #FF1493; font-size: 1rem"></i>
            感谢您的阅读----------
            </div>
        
    </div>





  
  <div class="my_post_copyright"> 
    <p><span>文章标题:</span><a href="/post/2b49c53b.html">LV09-03-linux-02-linux内核移植</a></p>
    <p><span>文章作者:</span><a href="/" title="欢迎访问 《苏木》 的学习笔记">苏木</a></p>
    <p><span>发布时间:</span>2023年07月07日 - 19:34</p>
    <p><span>最后更新:</span>2025年06月14日 - 00:25</p>
    <p><span>原始链接:</span><a href="/post/2b49c53b.html" title="LV09-03-linux-02-linux内核移植">https://sumumm.github.io/post/2b49c53b.html</a></p>
    <p><span>许可协议:</span><i class="fab fa-creative-commons"></i> <a rel="license" href= "https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank" title="Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)">署名-非商业性使用-禁止演绎 4.0 国际</a> 转载请保留原文链接及作者。</p>  
  </div>
  


          <div class="post-tags">
              <a href="/tags/LV09-uboot%E4%B8%8Elinux/" rel="tag"><i class="fa fa-tag"></i> LV09-uboot与linux</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/post/5db09a14.html" rel="prev" title="LV09-03-linux-03-USB驱动移植">
                  <i class="fa fa-angle-left"></i> LV09-03-linux-03-USB驱动移植
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/post/1234bbb.html" rel="next" title="LV09-03-linux-01-内核加载">
                  LV09-03-linux-01-内核加载 <i class="fa fa-angle-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">

  <div class="copyright">
    &copy; 2017 – 
    <span itemprop="copyrightYear">2025</span>
    <span class="with-love">
      <i class="fa fa-heart"></i>
    </span>
    <span class="author" itemprop="copyrightHolder">苏木</span>
  </div>
<div class="wordcount">
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-line"></i>
    </span>
      <span>站点总字数：</span>
    <span title="站点总字数">3.7m</span>
  </span>
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
      <span>站点阅读时长 &asymp;</span>
    <span title="站点阅读时长">225:26</span>
  </span>
</div>




    <span id="sitetime"></span>
    <script defer language=javascript>
        function siteTime()
        {
            window.setTimeout("siteTime()", 1000);
            var seconds = 1000;
            var minutes = seconds * 60;
            var hours = minutes * 60;
            var days = hours * 24;
            var years = days * 365;
            var today = new Date();
            var todayYear = today.getFullYear();
            var todayMonth = today.getMonth()+1;
            var todayDate = today.getDate();
            var todayHour = today.getHours();
            var todayMinute = today.getMinutes();
            var todaySecond = today.getSeconds();
            /*==================================================
            Date.UTC() -- 返回date对象距世界标准时间(UTC)1970年1月1日午夜之间的毫秒数(时间戳)
            year        - 作为date对象的年份，为4位年份值
            month       - 0-11之间的整数，做为date对象的月份
            day         - 1-31之间的整数，做为date对象的天数
            hours       - 0(午夜24点)-23之间的整数，做为date对象的小时数
            minutes     - 0-59之间的整数，做为date对象的分钟数
            seconds     - 0-59之间的整数，做为date对象的秒数
            microseconds - 0-999之间的整数，做为date对象的毫秒数
            ==================================================*/
            var t1 = Date.UTC(2017, 
                              5, 
                              19, 
                              0, 
                              0, 
                              0); //北京时间
            var t2 = Date.UTC(todayYear,todayMonth,todayDate,todayHour,todayMinute,todaySecond);
            var diff = t2-t1;
            var diffYears = Math.floor(diff/years);
            var diffDays = Math.floor((diff/days)-diffYears*365);
            var diffHours = Math.floor((diff-(diffYears*365+diffDays)*days)/hours);
            var diffMinutes = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours)/minutes);
            var diffSeconds = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours-diffMinutes*minutes)/seconds);
            document.getElementById("sitetime").innerHTML="已在这里 "+diffYears+" 年 "+diffDays+" 天 "+diffHours+" 小时 "+diffMinutes+" 分钟 "+diffSeconds+" 秒";
        }
        siteTime();
    </script>



    </div>
  </footer>

  
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up fa-lg"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/next-theme-pjax/0.6.0/pjax.min.js" integrity="sha256-vxLn1tSKWD4dqbMRyv940UYw4sXgMtYcK6reefzZrao=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.28/fancybox/fancybox.umd.js" integrity="sha256-ytMJGN3toR+a84u7g7NuHm91VIR06Q41kMWDr2pq7Zo=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/lozad.js/1.16.0/lozad.min.js" integrity="sha256-mOFREFhqmHeQbXpK2lp4nA3qooVgACfh88fpJftLBbc=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script><script src="/js/pjax.js"></script>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/hexo-generator-searchdb/1.4.1/search.js" integrity="sha256-1kfA5uHPf65M5cphT2dvymhkuyHPQp5A53EGZOnOLmc=" crossorigin="anonymous"></script>
<script src="/js/third-party/search/local-search.js"></script>




  <script src="/js/third-party/fancybox.js"></script>

  <script src="/js/third-party/pace.js"></script>


  




  

  <script class="next-config" data-name="enableMath" type="application/json">true</script><script class="next-config" data-name="mathjax" type="application/json">{"enable":true,"tags":"none","js":{"url":"https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.2/es5/tex-mml-chtml.js","integrity":"sha256-MASABpB4tYktI2Oitl4t+78w/lyA+D7b/s9GEP0JOGI="}}</script>
<script src="/js/third-party/math/mathjax.js"></script>


 
        <div id="click-show-text"
            data-mobile = false
            data-text = 富强,民主,文明,和谐,自由,平等,公正,法制,爱国,敬业,诚信,友善
            data-fontsize = 15px
            data-random= false>
        </div>
       

      
        <script async src=https://cdn.jsdelivr.net/npm/hexo-next-mouse-effect@latest/click/showText.js></script>
      

      
    




    <script async src="/js/fancybox_param.js"></script>





<!-- APlayer本体 -->



</body>
</html>
